package com.qst.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qst.Service.AdminUserService;
import com.qst.Vo.AdminUserVo;
import com.qst.pojo.Admin;
import com.qst.pojo.Room;
import com.qst.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @packageName:com.qst.controller
 * @className:AdminUserController
 * @Description:
 * @author:zhangyu
 * @date 2021/6/20 22:25
 **/

@Controller
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;

    @RequestMapping(value = "/adminuserAll")
    @ResponseBody
    private Map<String, Object> adminuserAll(AdminUserVo adminUserVo) {
        PageHelper.startPage(adminUserVo.getPage(),adminUserVo.getLimit());
        List<User> users = adminUserService.adminfinduser(adminUserVo);
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<User> pageInfo = new PageInfo<User>(users);
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        System.out.println(map);
        return map;
    }

    @RequestMapping(value = "/addadminuser")
    @ResponseBody
    public Map<String,Object> addadminuser(User user){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminUserService.addadminuser(user)>0){
            map.put("success",true);
            map.put("message","添加成功");
        }else{
            map.put("success",false);
            map.put("message","添加失败");
        }
        return map;


    }
    @RequestMapping(value = "/updateadminuser")
    @ResponseBody
    public Map<String,Object> updateadminuser(User user){
        Map<String,Object> map = new HashMap<String, Object>();
        if(adminUserService.updateadminuser(user)>0){
            map.put("success",true);
            map.put("message","修改成功");
        }else{
            map.put("success",false);
            map.put("message","修改失败");
        }
        return map;


    }
    @RequestMapping(value = "/deleteadminuser")
    @ResponseBody
    public Map<String,Object> deleteadminuser(int id) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (adminUserService.deleteadminuser(id) > 0) {
            map.put("success", true);
            map.put("message", "删除成功");
        } else {
            map.put("success", false);
            map.put("message", "删除失败");
        }
        return map;
    }


}

